<template>
  <div class="page-miH page-bgBack">
    <PageHeader @back="$router.go(-1)" subTitle="返回"> 客户详情 </PageHeader>
    <div class="name">
      {{ $route.query.name }} <span class="t1" v-if="isSign">签约</span><span class="t2" v-else>潜在</span>
      <div class="btn" v-if="!isSign">
        <a-button type="primary" @click="onSigning"> 签约客户 </a-button>
      </div>
    </div>
    <div class="box">
      <a-tabs type="card" default-active-key="information" @change="(v) => (componentName = v)">
        <a-tab-pane :key="item.type" v-for="item in numArr">
          <span slot="tab">
            <a-badge :count="item.num" :offset="[5, -2]">{{ item.name }}</a-badge>
          </span>
        </a-tab-pane>
      </a-tabs>
      <div :is="componentName" :address="address" @upDate="upDate" @upDateAddress="upDateAddress"></div>
    </div>
  </div>
</template>

<script>
import information from "./information";
import visit from "./visit";
import distribution from "./distribution";
export default {
  components: {
    information,
    visit,
    distribution
  },
  data() {
    return {
      componentName: "information",
      numArr: [
        { type: "information", name: "客户信息", num: 0 },
        { type: "visit", name: "拜访记录", num: 0 },
        { type: "distribution", name: "分配记录", num: 0 }
      ],
      address: "",
      isSign: false
    };
  },
  created() {
    if (parseInt(this.$route.query.type) === 1) {
      this.isSign = false;
    }
    if (parseInt(this.$route.query.type) === 2) {
      this.isSign = true;
    }
  },
  methods: {
    upDate(e) {
      this.isSign = e;
    },
    upDateAddress(e) {
      this.address = e;
    },
    onSigning() {
      const path = this.$route.path.split("/");
      this.$router.push({ path: `/clientele/${path[2]}/edit`, query: { type: 2, id: this.$route.query.id } });
    }
  }
};
</script>

<style lang="scss" scoped>
.box {
  padding: 24px;
  ::v-deep.ant-tabs-tab {
    line-height: 60px;
    padding-top: 0px;
    height: 60px;
    margin-right: 12px !important;
  }
  ::v-deep.ant-tabs-bar {
    margin-bottom: 24px !important;
  }
}
.name {
  font-size: 18px;
  color: #3c3d43;
  font-weight: 500;
  margin: 24px 0 0 24px;
  position: relative;
  span {
    font-size: 12px;
    font-weight: 400;
    color: #767885;
  }
  i {
    font-size: 12px;
    color: #767885;
    margin-left: 14px;
  }
  .t1 {
    display: inline-block;
    width: 40px;
    height: 18px;
    background: #4686ff;
    border-radius: 2px;
    text-align: center;
    line-height: 18px;
    font-size: 10px;
    color: #fff;
    margin-left: 8px;
    vertical-align: middle;
  }
  .t2 {
    display: inline-block;
    width: 40px;
    height: 18px;
    background: #ffbb00;
    border-radius: 2px;
    text-align: center;
    line-height: 18px;
    font-size: 10px;
    color: #fff;
    margin-left: 8px;
    vertical-align: middle;
  }
  .btn {
    position: absolute;
    right: 48px;
    top: 0;
  }
}
</style>
